﻿using Leeder.Logger;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace LeederHttp
{
    /// <summary>
    /// http帮助类
    /// </summary>
    public class HttpHelper
    {
        /// <summary>
        /// 日志
        /// </summary>
        LogOperate LogObj => Log.GetLogger(this.GetType());
        /// <summary>
        /// post
        /// 请求
        /// </summary>
        /// <param name="url"></param>
        /// <param name="method"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        [Obsolete]
        public static string RequestBody(string url, string method, string body)
        {

            string strReturn = "";
            try
            {
                var req = (HttpWebRequest)WebRequest.Create(url);
                req.Method = method;
                req.ContentType = "application/json; charset=utf-8";
                req.KeepAlive = false;
                byte[] bs = Encoding.UTF8.GetBytes(body);
                req.ContentLength = bs.Length;
                Stream reqStream = req.GetRequestStream();
                reqStream.Write(bs, 0, bs.Length);
                reqStream.Close();
                var res = req.GetResponse() as HttpWebResponse;
                StreamReader reader = new StreamReader(res.GetResponseStream(), Encoding.UTF8);
                strReturn = reader.ReadToEnd();
                reader.Close();
                res.Close();
            }
            catch (Exception ex)
            {
                //LogObj.Error(ex.Message);
            }
            return strReturn;
        }

    }
}
